<?php
/*
 * 在线店用户中心
 * @arrange WL
 * @package ixdcw
 * @file    store.inc.php
 */
defined('IN_IXDCW') or exit('Access Denied');
login();
if($_groupid <= 5) Prompt::message('您的会员级别权限不够，建议您升级会员级别', url('member/grade'));
require DT_CORE.'/'.$module.'/common.inc.php';
$do = new StoreModule(40);
$do->setUserid($_userid);
$item = $do->getOne();
$business = '';
if(isset($post)) {
	if ($do->pass($post)){
		if(!$item){
			$post['status'] = 2;
			if($do->add($post)) $return['success'] = 1;
			$return['message'] = '在线店信息提交成功,请等待审核';
			$do->ajaxReturn($return);
		}else{
			if($item['status'] ==0 || $item['status'] == 1) $post['status'] = 2;
			if($do->edit($post)) $return['success'] = 1;
			if($post['status'] ==2){
				$return['message'] = '在线店信息提交成功,请等待审核';
			}else{
				$return['message'] = '更新在线店信息成功';
			}
			$do->ajaxReturn($return);
		}
	} else {
		$return['success'] = 0;
		$return['message'] = $do->getErrmsg();
		$do->ajaxReturn($return);
	}
}else{
	$LBRANDS  = AutoBrand::getLetterBrands();
	$BRANDS = AutoBrand::getBrands();
	$CATEGORY = PCache::read('category-40.php');
	$cartree = Ext::genTree($CATEGORY,'catid');
	extract($item);
	$userinfo = userinfo($_username);
	$company  = $company ? $company : $userinfo['company'];
	$address  = $address ? $address : $userinfo['address'];
    $telephone = $telephone ? $telephone : $userinfo['telephone'];
	$areaid  = $areaid ? $areaid : $userinfo['areaid'];
	// 已经选择的品牌
	$arbids = explode(',', $arbid);
	$selectedBrands = array();
	foreach($arbids as $arbid) {
		if (isset($BRANDS[$arbid])) {
			$selectedBrands[$arbid] = $BRANDS[$arbid];
		}
	}
	$cates = $catid ? explode(',', $catid) : array();

	include template('store', $module);
}

